home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 822 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  2.7 KB

  1. Path: newshost.lanl.gov!tanmoy
  2. From: tanmoy@qcd.lanl.gov (Tanmoy Bhattacharya)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: warning: possibly incorrect assignment
  5. Date: 09 Jan 1996 16:30:50 GMT
  6. Organization: Los Alamos National Laboratory
  7. Message-ID: <TANMOY.96Jan9093050@qcd.lanl.gov>
  8. References: <Pine.OSF.3.91.960109091920.6447A-100000@io.UWinnipeg.ca>
  9. NNTP-Posting-Host: qcd.lanl.gov
  10. Mime-Version: 1.0
  11. Content-Type: text
  12. In-reply-to: Bill Simpson's message of Tue, 9 Jan 1996 09:26:35 -0600
  13.  
  14. --text follows this line--
  15. In article <Pine.OSF.3.91.960109091920.6447A-100000@io.UWinnipeg.ca>
  16. Bill Simpson <wsimpson@uwinnipeg.ca> writes: 
  17. <snip>
  18.    I get the above warning when I compile code using the following
  19.    function.  It flags the **** line.
  20. <snip>
  21.    ****        while(fp=fopen(file_name,"r"))
  22. <snip>
  23.    How can I write this code so the compiler does not issue this warning?
  24.  
  25. Unfortunately compilers are allowed (by the standard) to issue
  26. as many more warnings than required as they please: it is a quality of
  27. implementation issue whether the warnings are useful. There is no
  28. general method of stopping a particular warning: but if an useless
  29. warning is very difficult to get rid off, I would instead get rid off
  30. the compiler.
  31.  
  32. In this case, I think the warning is useful. The compiler is wondering
  33. whether you perhaps mistyped = for ==. (It would not have wondered so
  34. if it knew about the usage patterns of fopen, but few compilers today
  35. treat the library functions as special.) You could probably get rid
  36. off the warning by not doing the assignment in the test condition, but
  37. that is slightly inconvenient in this case.
  38.  
  39. Most compilers shut up if the questionable assignment is inside a
  40. layer of parentheses, e.g. `while((fp=fopen(file_name,"r")))', or is a
  41. subexpression, e.g., `while((fp=fopen(file_name,"r")) != NULL)'. I
  42. often use the first form when dealing with such helpful compilers.
  43.  
  44.    Please don't suggest I just tell the compiler to shut up.  In general
  45.    the warnings are useful.  I do not want to just ignore the warning either.
  46.    I have the FAQ and haven't seen this discussed.
  47.  
  48. If that is true, it should be included in the FAQ.
  49.  
  50.    (Any other improvements to above code segment welcomed)
  51.  
  52. Haven't looked at the code, but remember that a file not being
  53. readable is no guarantee of its non-existence.
  54.  
  55. Cheers
  56. Tanmoy
  57. --
  58. tanmoy@qcd.lanl.gov(128.165.23.46) DECNET: BETA::"tanmoy@lanl.gov"(1.218=1242)
  59. Tanmoy Bhattacharya O:T-8(MS B285)LANL,NM87545 H:#9,3000,Trinity Drive,NM87544
  60. Others see <gopher://yaleinfo.yale.edu:7700/00/Internet-People/internet-mail>,
  61. <http://alpha.acast.nova.edu/cgi-bin/inmgq.pl>or<ftp://csd4.csd.uwm.edu/pub/
  62. internetwork-mail-guide>. -- <http://nqcd.lanl.gov/people/tanmoy/tanmoy.html>
  63. fax: 1 (505) 665 3003   voice: 1 (505) 665 4733    [ Home: 1 (505) 662 5596 ]
  64.